//
// Created by gj on 16-2-18.
//

#include "SharePointer.h"

#include <unistd.h>

#ifdef FLAG_UNIT_TESTING

void share_pointer_unit_testing() {
    LOG_CREATE_FUNC_DEBUG("test");
    LOG_I_FILE_FUNC("--> test start!")
    LOG_I(LOG_SEPARATOR)
    int *ip = new int(1);

    SharePointer<int> sharePointer(ip);
    sharePointer = sharePointer;
    for (int i = 0; i < 10; ++i) {
        LOG_I("--> test 1 : %d", i)
        SharePointer<int> a(sharePointer);
        a = sharePointer;
        sharePointer = a;
    }
    sleep(1);
    LOG_I_FILE_FUNC("--> test 1 end...")
    LOG_I(LOG_SEPARATOR)
    int *ipa = new int(1);
    SharePointer<int> c = sharePointer;
    SharePointer<int> b(ipa);
    sharePointer = b;
    for (int i = 0; i < 10; ++i) {
        int *ipb = new int(1);
        SharePointer<int> a(ipb);
        sharePointer = a;
        a = sharePointer;
        sharePointer = a;
    }
    sleep(1);
    LOG_I_FILE_FUNC("--> test 2 end...")
    LOG_I(LOG_SEPARATOR)
    // c,s,b --> ipb
    for (int i = 0; i < 10; ++i) {
        LOG_I("--> test 3 : %d", i)
        SharePointer<int> a(sharePointer);
        LOG_I("--> test 3 : %d", i)
        c = b;
        LOG_I("--> test 3 : %d", i)
        c = a;
        LOG_I("--> test 3 : %d", i)
        sharePointer = c;
        LOG_I("--> test 3 : %d", i)
        a = b;
        LOG_I("--> test 3 : %d", i)
        b = sharePointer;
        LOG_I("--> test 3 : %d", i)
    }
    sleep(1);
    LOG_I_FILE_FUNC("--> test 3 end...")
    LOG_I(LOG_SEPARATOR)
}

#endif
